#include<bits/stdc++.h>
using namespace std;
int t;//20
int n,m;//100000
int l/*1000000*/,V;//1000
int d[100005],v[100005],a[100005],p[100005];
int pre[1000005],suf[1000005];
void subtask1(){
    int maxm=-1;
    for(int i=1;i<=m;i++)maxm=max(maxm,p[i]);
    int ans=0;
    for(int i=1;i<=n;i++){
        if(v[i]>V&&d[i]<=maxm)ans++;
    }
    cout<<ans<<" "<<m-1<<endl;
}
void subtask2(){
    int maxm=-1;
    for(int i=1;i<=m;i++)maxm=max(maxm,p[i]);
    int ans=0;
    for(int i=1;i<=n;i++){
        int k=0;
        if(v[i]>V){
            if(d[i]<=maxm)ans++;
        }else{
            k=V*V-v[i]*v[i];
            if(k<2*a[i]*(maxm-d[i]))ans++;
        }
    }
    cout<<ans<<" "<<m-1<<endl;
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--){
        memset(pre,-1,sizeof(pre));memset(suf,-1,sizeof(suf));
        scanf("%d%d%d%d",&n,&m,&l,&V);
        bool f1=1,f2=1;
        for(int i=1;i<=n;i++){
            scanf("%d%d%d",&d[i],&v[i],&a[i]);
            if(a[i]!=0)f1=0;
            if(a[i]<=0)f2=0;
        }
        //int ans=0;
        for(int i=1;i<=m;i++){
            scanf("%d",&p[i]);
            //pre[p[i]]=suf[p[i]]=i;
        }
        if(f1){
            subtask1();
        }else if(f2){
            subtask2();
        }
        /*for(int i=1;i<=l;i++){
            if(pre[i]==-1)pre[i]=pre[i-1];
            if(suf[l-i]==-1)suf[l-i]=suf[l-i+1];
        }
        for(int i=1;i<=n;i++){
            if(a[i]==0){
                if(v[i]>V&&suf[d[i]]!=-1){
                    ans++;
                }
            }else if(a[i]>0){
                int k=(V*V-v[i]*v[i]);
                if(v[i]>V&&suf[d[i]]!=-1){
                    ans++;
                }else if(k<n&&suf[d[i]+(k+2*a[i])/(2*a[i])]!=-1){
                    ans++;
                }
            }else{
                if(v[i]>V){
                    int k=V*V-v[i]*v[i];
                    if(pre[d[i]]!=pre[d[i]+k/2/a[i]]){
                        ans++;
                    }
                }
            }
        }
        cout<<ans<<endl;*/
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}